package com.ewhale.feitengguest.ui.user.mine

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import butterknife.BindView
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.utils.slidingtab.SlidingTabLayout
import com.simga.library.activity.MBaseActivity
import com.simga.library.base.IPresenter
import com.simga.library.base.IView
import kotlinx.android.synthetic.main.activity_mytask.*
import java.util.*

class MyTaskActivity : MBaseActivity<IPresenter?>(), IView {

    private val mFragments = ArrayList<Fragment>()
    private var mAdapter: MyPagerAdapter? = null
    private val mTitles = arrayOf("全部", "待完成", "待审核", "不及格", "已完成")
    override fun onGetBundle(bundle: Bundle) {}
    override fun getViewId(): Int {
        return R.layout.activity_mytask
    }

    override fun init(savedInstanceState: Bundle?) {
        setTitle("我的任务")
        for (i in mTitles.indices) {
            mFragments.add(MyTaskFragment.getInstance(i + 1))
        }
        mAdapter = MyPagerAdapter(supportFragmentManager)
        acty_main_vp!!.run {
            adapter = mAdapter
            offscreenPageLimit = 5
        }
        acty_main_tab!!.setViewPager(acty_main_vp)
    }

    override fun isUseBaseTitleBar(): Boolean {
        return true
    }

    override fun initListener() {}
    override fun showProLoading() {}
    override fun dimissProLoading() {}
    override fun showErrorMessage(postCode: Int, code: String, message: String) {}
    private inner class MyPagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) {
        override fun getCount(): Int {
            return mFragments.size
        }

        override fun getPageTitle(position: Int): CharSequence? {
            return mTitles[position]
        }

        override fun getItem(position: Int): Fragment {
            return mFragments[position]
        }
    }

    companion object {
        fun open(context: MBaseActivity<*>) {
            context.startActivity(null, MyTaskActivity::class.java)
        }
    }
}